package com.nacos.config.instance;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;

import java.io.IOException;
import java.util.Properties;

/**
 * @author chn
 * @version 1.0
 * @Feature: 注册实例
 * @data 2024/9/12 15:23
 */
public class registerInstance {
    public static void main(String[] args) throws NacosException, IOException {
        Properties properties = new Properties();
        properties.put("serverAddr", "127.0.0.1:8848");
        properties.put("username", "nacos");
        properties.put("password", "nacos");

        ConfigService configService = NacosFactory.createConfigService(properties);
        NamingService namingService = NacosFactory.createNamingService(properties);
        try {
            namingService.registerInstance("test1", "127.0.0.1", 8888);
            System.out.println("register instance success");
        } catch (NacosException e) {
            System.out.println("register instance failed");
        }
    }
}
